home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / regex.h < prev    next >
C/C++ Source or Header  |  1990-05-19  |  11KB  |  235 lines

  1. /* Definitions for data structures callers pass the regex library.
  2.    Copyright (C) 1985 Free Software Foundation, Inc.
  3.  
  4.                NO WARRANTY
  5.  
  6.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  7. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  8. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  9. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  10. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  11. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  13. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  14. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  15. CORRECTION.
  16.  
  17.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  18. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  19. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  20. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  21. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  22. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  23. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  24. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  25. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  26. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  27.  
  28.         GENERAL PUBLIC LICENSE TO COPY
  29.  
  30.   1. You may copy and distribute verbatim copies of this source file
  31. as you receive it, in any medium, provided that you conspicuously and
  32. appropriately publish on each copy a valid copyright notice "Copyright
  33. (C) 1985 Free Software Foundation, Inc."; and include following the
  34. copyright notice a verbatim copy of the above disclaimer of warranty
  35. and of this License.  You may charge a distribution fee for the
  36. physical act of transferring a copy.
  37.  
  38.   2. You may modify your copy or copies of this source file or
  39. any portion of it, and copy and distribute such modifications under
  40. the terms of Paragraph 1 above, provided that you also do the following:
  41.  
  42.     a) cause the modified files to carry prominent notices stating
  43.     that you changed the files and the date of any change; and
  44.  
  45.     b) cause the whole of any work that you distribute or publish,
  46.     that in whole or in part contains or is a derivative of this
  47.     program or any part thereof, to be licensed at no charge to all
  48.     third parties on terms identical to those contained in this
  49.     License Agreement (except that you may choose to grant more
  50.     extensive warranty protection to third parties, at your option).
  51.  
  52.     c) You may charge a distribution fee for the physical act of
  53.     transferring a copy, and you may at your option offer warranty
  54.     protection in exchange for a fee.
  55.  
  56.   3. You may copy and distribute this program or any portion of it in
  57. compiled, executable or object code form under the terms of Paragraphs
  58. 1 and 2 above provided that you do the following:
  59.  
  60.     a) cause each such copy to be accompanied by the
  61.     corresponding machine-readable source code, which must
  62.     be distributed under the terms of Paragraphs 1 and 2 above; or,
  63.  
  64.     b) cause each such copy to be accompanied by a
  65.     written offer, with no time limit, to give any third party
  66.     free (except for a nominal shipping charge) a machine readable
  67.     copy of the corresponding source code, to be distributed
  68.     under the terms of Paragraphs 1 and 2 above; or,
  69.  
  70.     c) in the case of a recipient of this program in compiled, executable
  71.     or object code form (without the corresponding source code) you
  72.     shall cause copies you distribute to be accompanied by a copy
  73.     of the written offer of source code which you received along
  74.     with the copy you received.
  75.  
  76.   4. You may not copy, sublicense, distribute or transfer this program
  77. except as expressly provided under this License Agreement.  Any attempt
  78. otherwise to copy, sublicense, distribute or transfer this program is void and
  79. your rights to use the program under this License agreement shall be
  80. automatically terminated.  However, parties who have received computer
  81. software programs from you with this License Agreement will not have
  82. their licenses terminated so long as such parties remain in full compliance.
  83.  
  84.   5. If you wish to incorporate parts of this program into other free
  85. programs whose distribution conditions are different, write to the Free
  86. Software Foundation at 1000 Mass Ave, Cambridge, MA 02138.  We have not yet
  87. worked out a simple rule that can be stated here, but we will often permit
  88. this.  We will be guided by the two goals of preserving the free status of
  89. all derivatives our free software and of promoting the sharing and reuse of
  90. software.
  91.  
  92.  
  93. In other words, you are welcome to use, share and improve this program.
  94. You are forbidden to forbid anyone else to use, share and improve
  95. what you give them.   Help stamp out software-hoarding!  */
  96.  
  97. /*
  98. Modified on 6-Jan-88 by K. E. Gorlen
  99.  
  100. Add C++ -style declarations for extern functions.
  101. */
  102.  
  103. #ifndef RE_NREGS
  104. #define RE_NREGS 10
  105. #endif
  106.  
  107. /* This data structure is used to represent a compiled pattern. */
  108.  
  109. struct re_pattern_buffer
  110.   {
  111.     char *buffer;    /* Space holding the compiled pattern commands. */
  112.     int allocated;    /* Size of space that  buffer  points to */
  113.     int used;        /* Length of portion of buffer actually occupied */
  114.     char *fastmap;    /* Pointer to fastmap, if any, or zero if none. */
  115.             /* re_search uses the fastmap, if there is one,
  116.                to skip quickly over totally implausible characters */
  117.     char *translate;    /* Translate table to apply to all characters before comparing.
  118.                Or zero for no translation.
  119.                The translation is applied to a pattern when it is compiled
  120.                and to data when it is matched. */
  121.     char fastmap_accurate;
  122.             /* Set to zero when a new pattern is stored,
  123.                set to one when the fastmap is updated from it. */
  124.     char can_be_null;   /* Set to one by compiling fastmap
  125.                if this pattern might match the null string.
  126.                It does not necessarily match the null string
  127.                in that case, but if this is zero, it cannot.
  128.                2 as value means can match null string
  129.                but at end of range or before a character
  130.                listed in the fastmap.  */
  131.   };
  132.  
  133. /* Structure to store "register" contents data in.
  134.  
  135.    Pass the address of such a structure as an argument to re_match, etc.,
  136.    if you want this information back.
  137.  
  138.    start[i] and end[i] record the string matched by \( ... \) grouping i,
  139.    for i from 1 to RE_NREGS - 1.
  140.    start[0] and end[0] record the entire string matched. */
  141.  
  142. struct re_registers
  143.   {
  144.     int start[RE_NREGS];
  145.     int end[RE_NREGS];
  146.   };
  147.  
  148. /* These are the command codes that appear in compiled regular expressions, one per byte.
  149.   Some command codes are followed by argument bytes.
  150.   A command code can specify any interpretation whatever for its arguments.
  151.   Zero-bytes may appear in the compiled regular expression. */
  152.  
  153. enum regexpcode
  154.   {
  155.     unused,
  156.     exactn,    /* followed by one byte giving n, and then by n literal bytes */
  157.     begline,   /* fails unless at beginning of line */
  158.     endline,   /* fails unless at end of line */
  159.     jump,     /* followed by two bytes giving relative address to jump to */
  160.     on_failure_jump,     /* followed by two bytes giving relative address of place
  161.                     to resume at in case of failure. */
  162.     finalize_jump,     /* Throw away latest failure point and then jump to address. */
  163.     maybe_finalize_jump, /* Like jump but finalize if safe to do so.
  164.                 This is used to jump back to the beginning
  165.                 of a repeat.  If the command that follows
  166.                 this jump is clearly incompatible with the
  167.                 one at the beginning of the repeat, such that
  168.                 we can be sure that there is no use backtracking
  169.                 out of repetitions already completed,
  170.                 then we finalize. */
  171.     dummy_failure_jump,  /* jump, and push a dummy failure point.
  172.                 This failure point will be thrown away
  173.                 if an attempt is made to use it for a failure.
  174.                 A + construct makes this before the first repeat.  */
  175.     anychar,     /* matches any one character */
  176.     charset,     /* matches any one char belonging to specified set.
  177.             First following byte is # bitmap bytes.
  178.             Then come bytes for a bit-map saying which chars are in.
  179.             Bits in each byte are ordered low-bit-first.
  180.             A character is in the set if its bit is 1.
  181.             A character too large to have a bit in the map
  182.             is automatically not in the set */
  183.     charset_not, /* similar but match any character that is NOT one of those specified */
  184.     start_memory, /* starts remembering the text that is matched
  185.             and stores it in a memory register.
  186.             followed by one byte containing the register number.
  187.             Register numbers must be in the range 0 through NREGS. */
  188.     stop_memory, /* stops remembering the text that is matched
  189.             and stores it in a memory register.
  190.             followed by one byte containing the register number.
  191.             Register numbers must be in the range 0 through NREGS. */
  192.     duplicate,    /* match a duplicate of something remembered.
  193.             Followed by one byte containing the index of the memory register. */
  194.     before_dot,     /* Succeeds if before dot */
  195.     at_dot,     /* Succeeds if at dot */
  196.     after_dot,     /* Succeeds if after dot */
  197.     begbuf,      /* Succeeds if at beginning of buffer */
  198.     endbuf,      /* Succeeds if at end of buffer */
  199.     wordchar,    /* Matches any word-constituent character */
  200.     notwordchar, /* Matches any char that is not a word-constituent */
  201.     wordbeg,     /* Succeeds if at word beginning */
  202.     wordend,     /* Succeeds if at word end */
  203.     wordbound,   /* Succeeds if at a word boundary */
  204.     notwordbound, /* Succeeds if not at a word boundary */
  205.     syntaxspec,  /* Matches any character whose syntax is specified.
  206.             followed by a byte which contains a syntax code, Sword or such like */
  207.     notsyntaxspec /* Matches any character whose syntax differs from the specified. */
  208.   };
  209.  
  210.  
  211. #ifndef c_plusplus
  212. extern char *re_compile_pattern ();
  213. /* Is this really advertised? */
  214. extern void re_compile_fastmap ();
  215. extern int re_search (), re_search_2 ();
  216. extern int re_match (), re_match_2 ();
  217. #else
  218. extern "C" {
  219. extern const char* re_compile_pattern(const char*, int size, struct re_pattern_buffer*);
  220. extern void re_compile_fastmap(struct re_pattern_buffer);
  221. extern int re_search(struct re_pattern_buffer*,    const char*, int size, int startpos, int range, struct re_registers*);
  222. extern int re_search_2(struct re_pattern_buffer*, const char*, int size1, const char*, int size2, int startpos, int range, struct re_registers*, int mstop);
  223. extern int re_match(struct re_pattern_buffer*, const char*, int size, int pos, struct re_registers*);
  224. extern int re_match_2(struct re_pattern_buffer*, const char* string1, int size1, const char* string2, int size2, int pos, struct re_registers*, int mstop);
  225. }
  226. #endif
  227.  
  228. /* 4.2 bsd compatibility (yuck) */
  229. extern char *re_comp ();
  230. extern int re_exec ();
  231.  
  232. #ifdef SYNTAX_TABLE
  233. extern char *re_syntax_table;
  234. #endif
  235.